package com.guldan.thrall.web.controller;

import com.guldan.core.dubbo.client.ResponseDTO;
import com.guldan.core.enums.*;
import com.guldan.core.response.ResponseJson;
import com.guldan.jaina.dto.users.UserCacheDTO;
import com.guldan.jaina.provider.IUserProvider;
import com.guldan.thrall.dto.CommonDataDTO;
import com.guldan.thrall.util.UserUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Created by Silas.
 * Date: 2016/12/4
 * Time: 11:37
 */
@Controller
@RequestMapping("/common")
public class CommonController {

    @Value("${cas.url}")
    private String casUrl;

    @Value("${app.url}")
    private String appUrl;

    @Autowired
    private IUserProvider iUserProvider;

    //获取全局公共信息
    @RequestMapping(value = "/data", method = RequestMethod.POST)
    @ResponseJson
    public
    @ResponseBody
    CommonDataDTO data(@CookieValue(value = "JSESSIONID", defaultValue = "") String JSESSIONID,
                       HttpServletRequest request,
                       HttpServletResponse response,
                       HttpSession session) {
        CommonDataDTO dto = new CommonDataDTO();
        dto.setAuditorTypeEn(AuditorTypeEn.getList());
        dto.setProjectRegisterBatchEn(ProjectRegisterBatchEn.getList());
        dto.setProjectRegisterEn(ProjectRegisterEn.getList());
        dto.setNewsTypeEn(NewsTypeEn.getList());
        dto.setFeedbackStateEn(FeedbackStateEn.getList());
        dto.setLoginOutUrl(casUrl + "loginOut?service=" + appUrl + "&jsessionid=" + session.getId());
        try {
            ResponseDTO<UserCacheDTO> responseDTO = iUserProvider.getUserCache(JSESSIONID);

            dto.setUser(responseDTO.getData());
        } catch (Exception ex) {

        }
        return dto;
    }

}
